package com.yyf.springboot2.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yyf.springboot2.common.ResultBean;
import com.yyf.springboot2.entity.TArticle;
import com.yyf.springboot2.service.TArticleService;
import org.apache.ibatis.scripting.xmltags.ForEachSqlNode;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yyf
 * @since 2019-05-29
 */
@Controller
@RequestMapping("/tArticle")
public class TArticleController {
    @Resource
    private TArticleService articleService;

    @GetMapping("/index")
    @ResponseBody
    public ResultBean getArticle(@PathVariable(value = "pageSize",required = false) Integer pageSize){
        Map<String,Object> map = new HashMap<>();

//        Integer pagesize = Integer.parseInt(pageSize);
      List<TArticle> artis = articleService.getindexArt(pageSize);
        System.out.println("/index");
      if(artis.size() > 0){
          map.put("artis",artis);
          JSONObject jsons = new JSONObject(map);
          return  ResultBean.build(200,"成功",jsons);
      }else {

          return ResultBean.build(200,"当前没有数据",null);
      }

    }
	
}
